//
//  YAYIMyHospitalCell.m
//  YAYIDoctor
//
//  Created by Veer on 16/5/13.
//
//

#import "YAYIMyHospitalCell.h"

#import "YAYIMyHospitalModel.h"


@interface YAYIMyHospitalCell()

@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *nameLbl;
@property (nonatomic, weak) UILabel *addressLbl;
@property (nonatomic, weak) UIView *lineView;
@property (nonatomic, weak) UIView *vertifyFlagView;
@property (nonatomic, weak) UILabel *vertifyFlagLbl;

@end

@implementation YAYIMyHospitalCell

- (void)setModel:(YAYIMyHospitalModel *)model
{
    _model = model;
    
    self.nameLbl.text = model.name;
    self.addressLbl.text = model.address;
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",API ,model.avatar];
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"hospital_icon"] options:SDWebImageRefreshCached];
    
//    self.vertifyFlagView.hidden = (model.wpv == 0);
    
    self.vertifyFlagLbl.text = model.wpv == 1 ? @"已认证" : @"未认证";
    self.vertifyFlagLbl.backgroundColor = model.wpv == 1 ? YAYIColor(104, 174, 240) : [UIColor lightGrayColor];
    
}

+ (instancetype)cellWith:(UITableView *)tableview
{
    static NSString *cellID = @"myHospitalCell";
    
    YAYIMyHospitalCell *cell = [tableview dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYIMyHospitalCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    return cell;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubview];
        
    }
    return self;
}


- (void)setupSubview
{
    
    self.contentView.clipsToBounds = YES;
    // 图标
    UIImageView *iconVw = [[UIImageView alloc] init];
    [self.contentView addSubview:iconVw];
    self.iconView = iconVw;
    
    // 医院名
    UILabel *nameLbl = [[UILabel alloc] init];
    nameLbl.font = [UIFont systemFontOfSize:17];
    [self.contentView addSubview:nameLbl];
    self.nameLbl = nameLbl;
    
    // 医院名
    UILabel *addressLbl = [[UILabel alloc] init];
    addressLbl.font = [UIFont systemFontOfSize:15];
    addressLbl.textColor = YAYIColor(116, 113, 113);
    [self.contentView addSubview:addressLbl];
    self.addressLbl = addressLbl;
    
    // 线
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = YAYICellLineColor;
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    
    //  认证标示
    UIView *vertifyFlagView = [[UIView alloc] init];
//    vertifyFlagView.hidden = YES;
    vertifyFlagView.frame = CGRectMake(SCREEN_width - 80, 0, 80, 80);
    vertifyFlagView.clipsToBounds = YES;
    [self.contentView addSubview:vertifyFlagView];
    self.vertifyFlagView = vertifyFlagView;
    
    UILabel *vertifyFlagLbl = [[UILabel alloc] init];
    vertifyFlagLbl.font = [UIFont systemFontOfSize:13];
    vertifyFlagLbl.textColor = [UIColor whiteColor];
    vertifyFlagLbl.textAlignment = NSTextAlignmentCenter;
    vertifyFlagLbl.text = @"已认证";
    vertifyFlagLbl.backgroundColor = YAYIColor(104, 174, 240);
    vertifyFlagLbl.size = CGSizeMake(80, 20);
    vertifyFlagLbl.center = CGPointMake(vertifyFlagView.width - 18, 18);
    vertifyFlagLbl.transform = CGAffineTransformMakeRotation(M_PI_4);
    [vertifyFlagView addSubview:vertifyFlagLbl];
    self.vertifyFlagLbl = vertifyFlagLbl;
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat margin = 15;
    // 设置frame
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(margin);
        make.bottom.mas_equalTo(-margin);
        make.left.mas_equalTo(margin);
        make.width.mas_equalTo(self.iconView.mas_height).multipliedBy(1.4);
    }];
    
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(20);
        make.top.mas_equalTo(margin);
    }];
    
    [self.addressLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLbl);
        make.top.mas_equalTo(self.nameLbl.mas_bottom).offset(10);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(SCREEN_width);
        make.left.mas_equalTo(0);
        make.bottom.equalTo(self.contentView);
    }];
}

@end
